package com.billdowney.dao.system;

import java.util.List;

import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import com.billdowney.dao.base.BaseJpaDao;
import com.billdowney.entity.system.SystemDirectory;

@Repository
public interface SystemDirectoryDao extends BaseJpaDao<SystemDirectory, String> {

	/**
	 * @Description: 更新数据的父级ID
	 * @param id       数据ID
	 * @param parentId 父级ID
	 * @return
	 * @author: 唐路钧
	 * @date: 2019年1月8日 下午4:47:09
	 */
	@Modifying
	@Query("UPDATE SystemDirectory SET parent_id=:parentId WHERE id=:id")
	public int updateDirectoryRelation(String id, String parentId);

	@Query(value = "SELECT sd.* FROM System_Directory sd WHERE sd.status=:status AND sd.type=:type AND (sd.parent_id='' OR sd.parent_id IS NULL)", nativeQuery = true)
	public List<SystemDirectory> getAll(String status, String type);

	@Query(value = "SELECT sd.* FROM System_Directory sd WHERE sd.status=:status AND sd.type=:type AND sd.parent_id=:parentId", nativeQuery = true)
	public List<SystemDirectory> getAll(String status, String type, String parentId);

}
